fix(cloudstack): get domain name information from network manager leases#6829
fix(cloudstack): get domain name information from network manager leases#6829ani-sinha wants to merge 3 commits intocanonical:mainfrom
Conversation
) DHCP leases can be directly obtained from network manager through appropriate command to the network manager cli. Add a couple of helper functions to get the lease information from network manager. In a subsequent patch, we will use the helper function from cloud stack datasource to get the lease information from network manager. Signed-off-by: Ani Sinha <anisinha@redhat.com>
Without mocking out dhcp.IscDhclient.get_newest_lease_file_from_distro, the functions on some platforms returns None. This means get_key_from_latest_lease() bails out early without calling parse_leases() to parse the lease file. Fix it. Signed-off-by: Ani Sinha <anisinha@redhat.com>
…ses (canonical#6829) Red Hat uses network manager as the supported dhcp client. If network manager cli is available, we should try to get domain name information directly from the network manager leases before asking distro specific dhcp client (dhcpcd by default). Signed-off-by: Ani Sinha <anisinha@redhat.com>
d9e4324 to
0056499
Compare
|
@holmanb @TheRealFalcon please review |
blackboxsw
left a comment
There was a problem hiding this comment.
Thanks for this proposal @ani-sinha. I think it is almost there, but needs a bit more support awareness of multi-NIC environments with two active interfacees and test coverage in test_dhcp.py.
There was a problem hiding this comment.
Pull request overview
This PR extends CloudStack hostname/FQDN discovery by adding NetworkManager (nmcli) DHCP lease parsing helpers and using them as an additional fallback when determining the DHCP-provided domain name. It also adjusts CloudStack unit tests to avoid a mock leak and to cover the new NetworkManager fallback behavior.
Changes:
- Add
nmcli-based DHCP4/DHCP6 lease parsing helpers incloudinit/net/dhcp.py. - Update
DataSourceCloudStack._get_domainname()to attempt NetworkManager leases after ISC dhclient leases. - Fix/extend unit tests to properly mock ISC dhclient lease file selection and to validate the NetworkManager path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cloudinit/net/dhcp.py |
Adds helper functions to run nmcli and parse NetworkManager DHCP lease output. |
cloudinit/sources/DataSourceCloudStack.py |
Adds a NetworkManager lease fallback when determining domain name for FQDN construction. |
tests/unittests/sources/test_cloudstack.py |
Updates mocks to avoid platform-dependent behavior and adds a test for the NetworkManager fallback path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
) DHCP leases can be directly obtained from network manager through appropriate command to the network manager cli. Add a couple of helper functions to get the lease information from network manager. In a subsequent patch, we will use the helper function from cloud stack datasource to get the lease information from network manager. Signed-off-by: Ani Sinha <anisinha@redhat.com> Co-authored-by: Chad Smith <chad.smith@canonical.com>
Without mocking out dhcp.IscDhclient.get_newest_lease_file_from_distro, the functions on some platforms returns None. This means get_key_from_latest_lease() bails out early without calling parse_leases() to parse the lease file. Fix it. Signed-off-by: Ani Sinha <anisinha@redhat.com>
…ses (canonical#6829) Red Hat uses network manager as the supported dhcp client. If network manager cli is available, we should try to get domain name information directly from the network manager leases before asking distro specific dhcp client (dhcpcd by default). Signed-off-by: Ani Sinha <anisinha@redhat.com> Co-authored-by: Chad Smith <chad.smith@canonical.com>
b95f3bd to
96a8a02
Compare
This is a series of three independent commits.
The first commit adds helper functions in dhcp module to get dhcp lease information from network manager.
The second commit fixes a mock leak in existing cloudstack unit test code.
The third commit adds ability in cloud stack code trying to get domain name use network manager leases as well (in addition to trying networtkd and isa dhclient as it does today already).
This change has been tested by our (Red Hat) customer. After the change, we see logs of this type:
Proposed Commit Message
Commit 1:
Commit 2:
Commit 3:
Merge type